<?php

require("include/top.php");

if(!empty($_SESSION['vendor']['id'])) {
	$tpl->display("header.tpl");
	$tpl->display("menu.tpl");
	

	//if(isset($_GET['page'])){
	//	$start=($_GET['page']-1)*20;
	//	$end=$_GET['page']*20-1;
	
	//}
	//else {
	//$start=0;
	//$end=5;
	
	//}


		if(!empty($_POST['class'])) {
				
					if($_POST['classer']==1) {
	
						$products=$_SESSION['vendor']->getProductsAll($start,$end);
						if(!empty($products)){
						$tpl->assign ('products',$products);
						$tpl->assign('select',1);
						
						}
					}
					if($_POST['classer']==2) {
	
						$products=$_SESSION['vendor']->getProductsReduc();
						if(!empty($products)){
						$tpl->assign ('products',$products);
						$tpl->assign('select',2);
						}
					}
						if($_POST['classer']==3) {
	
							$products=$_SESSION['vendor']->getSmallStock();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',3);
						}
					}
					
					
						if($_POST['classer']==4) {
	
							$products=$_SESSION['vendor']->getMostSolded();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',4);
						}
					}
					
						if($_POST['classer']==5) {
	
							$products=$_SESSION['vendor']->getMostSeen();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',5);
						}
					}
						if($_POST['classer']==6) {
	
							$products=$_SESSION['vendor']->getMostWL();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',6);
						}
					}
						if($_POST['classer']==7) {
	
							$products=$_SESSION['vendor']->getProductsOnline();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',7);
						}
					}
					if($_POST['classer']==8) {
	
							$products=$_SESSION['vendor']->getProductsOffline();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',8);
						}
					}
				}
				elseif(!empty($_POST['search'])) {
					$results=Search::searchProducts($_POST['keyword']);
					foreach($results as $product) {
						
						if($product['vendor']['id']==$_SESSION['vendor']['id']) {
						$products[]=$product;
						
						
						}
					}
					$tpl->assign ('products',$products);
					$tpl->assign('select',1);
				}
	
				else {
				//$total=$_SESSION['vendor']->getProductsAll();
				$products= $_SESSION['vendor']->getProductsAll($start,$end);
				$tpl->assign ('products',$products);
				$tpl->assign('select',1);
				}
				//$nombreDeMessagesParPage=5;
				//$nb = ceil(sizeof($products) / $nombreDeMessagesParPage);
				
				//$pages=array();
				//$i=1;
				//while($i <= $nb) {
				
				//$pages[]=$i;
				//$i++;
				
				//}
				
				//$tpl->assign('pages',$pages);
				$tpl->display("listing_products.tpl");
				


$tpl->display("footer.tpl");
}
else {header('Location:login.php');}
	
require("include/bottom.php");	



?>